package com.atguigu.crowd.handler;

import com.atguigu.crowd.entity.vo.DetailProjectVO;
import com.atguigu.crowd.entity.vo.PortalTypeVO;
import com.atguigu.crowd.entity.vo.ProjectVO;
import com.atguigu.crowd.service.api.ProjectService;
import com.atguigu.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProjectProviderHandler {

    @Autowired
    private ProjectService projectService;

    @RequestMapping("/get/project/detail/remote/{projectId}")
    public ResultEntity<DetailProjectVO> getDetailProjectVo(@PathVariable("projectId") Integer projectId){
        try {
            DetailProjectVO detailProjectVo = projectService.getDetailProjectVo(projectId);
            return ResultEntity.successWithData(detailProjectVo);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeRemote(){

        try {
            List<PortalTypeVO> portalTypeVo = projectService.getPortalTypeVo();
            return ResultEntity.successWithData(portalTypeVo);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

      @RequestMapping("/save/project/vo/remote")
      ResultEntity<String> saveProject(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId){

          try {
              projectService.saveProject(projectVO, memberId);
              return ResultEntity.successWithoutData();
          } catch (Exception e) {
              e.printStackTrace();
              return ResultEntity.failed(e.getMessage());
          }
      }
}
